package com.lv.suyiyong.hfrwork.ui

import android.Manifest
import android.view.View
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.lv.common.base.BaseActivity
import com.lv.common.utils.ARoutUtils
import com.lv.common.utils.StatusBarUtil

import com.lv.service.repo.UserDbHelper
import com.lv.service.repo.UserInfo
import com.lv.suyiyong.hfrwork.R
import com.lv.suyiyong.hfrwork.databinding.ActivityConsealSettingBinding
import com.permissionx.guolindev.PermissionX

/**
 * 作者： ygx
 * 创建日期：2023/5/6 10:33 AM
 * 签名： 天行健，君子以自强不息；地势坤，君子以厚德载物。
 * -    _              _           _     _   ____  _             _ _
 * -   / \   _ __   __| |_ __ ___ (_) __| | / ___|| |_ _   _  __| (_) ___
 * -  / _ \ | '_ \ / _` | '__/ _ \| |/ _` | \___ \| __| | | |/ _` | |/ _ \
 * - / ___ \| | | | (_| | | | (_) | | (_| |  ___) | |_| |_| | (_| | | (_) |
 * -/_/   \_\_| |_|\__,_|_|  \___/|_|\__,_| |____/ \__|\__,_|\__,_|_|\___/
 * <p>
 * You never know what you can do until you try !
 * ----------------------------------------------------------------
 * 描述：隐私设置
 */
@Route(path = ARoutUtils.ConsealSettingActivity)
class ConsealSettingActivity : BaseActivity<ActivityConsealSettingBinding>(),
    View.OnClickListener {
    @Autowired(name = "userinfo")
    @JvmField
    var mUserInfo: UserInfo? = null
    override fun getLayoutRes() = R.layout.activity_conseal_setting
    override fun initView() {
        super.initView()
        initStatusBar(this, true, true)
        ARouter.getInstance().inject(this)
        mBinding.apply {
            StatusBarUtil.setHeightAndPadding(this@ConsealSettingActivity, titleBar)
            titleBar.onClickBackIcon { finish() }
            titleBar.setTitle("隐私设置")
//            viewLocation.setOnClickListener(this@ConsealSettingActivity)
            viewCamera.setOnClickListener(this@ConsealSettingActivity)
            viewPic.setOnClickListener(this@ConsealSettingActivity)
            viewVideo.setOnClickListener(this@ConsealSettingActivity)
            viewRecome.setOnClickListener(this@ConsealSettingActivity)
        }
    }


    override fun initConfig() {
        super.initConfig()
        UserDbHelper.getLiveUserInfo(this@ConsealSettingActivity).observeKt {
            mUserInfo = it
            checkRecom()
        }

    }

    override fun onResume() {
        super.onResume()
        checkPermission()
    }

    private fun checkRecom() {
//        val isrecommend = mUserInfo?.isrecommend
//        if (isrecommend == "1") {
//            mBinding.tvRecomeState.text = "已允许"
//        } else {
//            mBinding.tvRecomeState.text = "去设置"
//        }
    }

    private fun checkPermission() {
//        val location = PermissionX.isGranted(this, Manifest.permission.ACCESS_COARSE_LOCATION)
        val camer = PermissionX.isGranted(this, Manifest.permission.CAMERA)
        val read = PermissionX.isGranted(this, Manifest.permission.READ_EXTERNAL_STORAGE)
        val recodeAudio = PermissionX.isGranted(this, Manifest.permission.RECORD_AUDIO)
//        if (location) {
//            mBinding.tvLocationState.text = "已允许"
//        } else {
//            mBinding.tvLocationState.text = "去设置"
//        }
        if (camer) {
            mBinding.tvCameraState.text = "已允许"
        } else {
            mBinding.tvCameraState.text = "去设置"
        }
        if (read) {
            mBinding.tvPicState.text = "已允许"
        } else {
            mBinding.tvPicState.text = "去设置"
        }
        if (recodeAudio) {
            mBinding.tvVideoState.text = "已允许"
        } else {
            mBinding.tvVideoState.text = "去设置"
        }
    }


    override fun initData() {
        super.initData()

    }

    override fun onClick(p0: View?) {
        when (p0?.id) {

            R.id.view_camera -> {
                ARouter.getInstance().build(ARoutUtils.ConsealSettingDecActivity)
                    .withString("mType", "2").navigation()
            }
            R.id.view_pic -> {
                ARouter.getInstance().build(ARoutUtils.ConsealSettingDecActivity)
                    .withString("mType", "3").navigation()
            }
            R.id.view_video -> {
                ARouter.getInstance().build(ARoutUtils.ConsealSettingDecActivity)
                    .withString("mType", "4").navigation()
            }
            R.id.view_recome -> {
                ARouter.getInstance().build(ARoutUtils.ConsealSettingDecActivity)
                    .withParcelable("userinfo", mUserInfo).withString("mType", "5").navigation()
            }


        }
    }


}